import java.io.PrintStream;
import java.util.Scanner;

/**
 * resolve o problem E do uva
 * @author Jonas Jeske www.inf.ufrgs.br/~jjeske
 * status: ACCEPTED!
 *
 */
public class Main {
	
	public static void main(String[] args){
		Main problemE = new Main();
		problemE.begin();		
	}

	/*
	 * Problem E - Ones
Given any integer 0 <= n <= 10000 not divisible by 2 or 5,
some multiple of n is a number
 which in decimal notation is a sequence of 1's.
  How many digits are in the smallest such a multiple of n? 
Sample input
3 / 111 =
7 / 1111111 =
9901 / 11111111111 = 

Output for sample input
3
6
12


	 */
	private void begin() {
		Scanner entrada = new Scanner(System.in);
		PrintStream saida = new PrintStream(System.out);
		long n;
		
		while(entrada.hasNext()){
			n = entrada.nextInt();
			saida.printf("%d\n", solveProblem(n));
		}
		
	}
	
	/**
	 * esse metodo resolve o problema
	 * @param n
	 * @return
	 */
	/*
	 *  111 / 3=
		1111111 / 7 =
		11111111111 / 9901 = 
	 */
	private static long solveProblem(long n){	
		long l = 1; //numero 1111111
		long i = 1; //quantidade de ums
		while(true){
			if(l < n){
				i++;
				l = (l * 10) + 1;								
			}
			if((l % n)==0){
				return i;
			} else {
				l = (l%n);
			}			
		}	
	}
	

}

	
